<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
	
	<%@ include file="../layout/header.jsp" %>
    
	<!-- 主体部分开始 -->
	<div class="container" style="margin-top:10px;">
		<div class="row">
			<h1>角色管理</h1>
			<div style="margin:10px auto;">
				<a type="button" class="btn btn-primary" href="${ctx}/role/addrole.jsp">新增</a>
				<a type="button" class="btn btn-danger" id="btnDeleteByIds" href="#" onclick="return deleteByIds();">删除</a>
			</div>
			<table class="table table-hover table-bordered">
				<tr>
					<th>
						<input type="checkbox" id="selectAll"/>
					</th>
					<th>角色编号</th>
					<th>角色名称</th>
					<th>角色描述</th>
					<th>操作</th>
				</tr>
				<c:forEach var="obj" items="${roles}">
					<tr>					
						<td>
							<c:if test="${obj.description ne '系统管理员'}">
								<input type="checkbox" name="selectOne" value="${obj.id}" />
							</c:if>
						</td>
						<td>${obj.id}</td>
						<td>${obj.roleName}</td>
						<td>${obj.description}</td>
						<td>
							<c:if test="${obj.description ne '系统管理员'}">
								<a class="btn btn-warning btn-sm" href="${ctx}/role.do?type=get&id=${obj.id}">编辑</a>
								<a class="btn btn-danger btn-sm" onclick="return confirm('确定要删除角色描述为【${obj.description}】的记录');" href="${ctx}/role.do?type=delete&id=${obj.id}">删除</a>
							</c:if>						
						</td>
					</tr>
				</c:forEach>
			</table>
		</div>
	</div>
	<!-- 主体部分结束 -->
	
    <%@ include file="../layout/footer.jsp" %>
    
    <script type="text/javascript">
    
    	function deleteByIds(){
    		var id_array = new Array();
    		$("input[name=selectOne]:checked").each(function(){
    			id_array.push($(this).val());
    		})
    		var ids = id_array.join(",");
    		if(ids != "" && ids.length > 0 ){
    			if(confirm("是否删除选中记录？")){
    				var href = "${ctx}/role.do?type=deleteByIds&ids=" + ids;    		
	        		//修改链接href属性
	        		$("#btnDeleteByIds").attr("href",href); 
	        		return true;
    			}else{
    				return false;
    			}
    		}else{
    			alert("请至少选择一条记录！");
    			return false;
    		}    		
    	}
    
    	$(function(){
    		$("#selectAll").click(function(){
    			$("input[name=selectOne]").each(function(){
    				$(this).prop("checked",!$(this).prop("checked"));
    			})
    		});
    	})
    </script>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    